package com.sunday.common.mybatis.plus.mvc;

import com.sunday.common.core.constants.LogConstants;
import com.sunday.common.core.remoting.rest.response.RestResponse;
import com.sunday.common.leaf.core.IdWorker;
import com.sunday.common.mybatis.plus.study.tool.db.Commodity;
import com.sunday.common.mybatis.plus.study.tool.db.CommodityMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

@Slf4j
@RestController
@RequestMapping("/test")
@AllArgsConstructor
public class CommodityApi {

    private CommodityMapper commodityMapper;

    @GetMapping("/insert")
    public RestResponse insert() {
        log.info(LogConstants.request_format);
        Commodity classify = new Commodity();
        classify.setId(IdWorker.getId());
        classify.setName("中文");
        classify.setCreateTime(LocalDateTime.now());
        commodityMapper.insert(classify);
        RestResponse response = RestResponse.ok();
        log.info(LogConstants.response_format_ack, response);
        return response;
    }

}